package sunyu.demo.spring.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.springframework.kafka.listener.MessageListener;
import sunyu.toolkit.core.LogKit;

/**
 * 消费者监听
 *
 * @author 孙宇
 */
public class KafkaConsumerListener implements MessageListener<String, String> {
    private static final Logger logger = LogKit.getLogger();

    @Override
    public void onMessage(ConsumerRecord<String, String> data) {
        logger.info("kafkaConsumer开始消费");
        String topic = data.topic();
        String key = data.key();
        String value = data.value();
        long offset = data.offset();
        int partition = data.partition();
        logger.info("topic:{}", topic);
        logger.info("key:{}", key);
        logger.info("value:{}", value);
        logger.info("offset:{}", offset);
        logger.info("partition:{}", partition);
        logger.info("kafkaConsumer消费结束");
    }
}
